<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */

$basedir = dirname(__FILE__);
require_once $basedir . '/../../classes/minime.php';

require_once 'vfsStream/vfsStream.php';

class MinimeTest extends PHPUnit_Framework_TestCase {

    public function testConfig() {

        $config = "[prod]
loglevel = debug
logpath = vfs://srv/minime.log

[date]
timezone = 'Europe/Paris'";
        
        # Register our virtual file system
        vfsStreamWrapper::register();
        
        # Create a new root directory
        $this->vfsRoot = $root = new vfsStreamDirectory('srv');
        $root->addChild(vfsStream::newFile('conf.ini')->withContent($config));
        $root->addChild(vfsStream::newFile('minime.log')->withContent(""));
        
        vfsStreamWrapper::setRoot($root);
        
        $configFilePath = vfsStream::url('srv/conf.ini');
        
        $confArray['conf_file'] = $configFilePath;
        
        MiniMe::initialize($confArray);
        
        $this->assertEquals("debug", MiniMe::$conf['prod']['loglevel']);
    }
    
    public function testGetLrddController() {
        MiniMe::initialize();
        $_GET['uri'] = urlencode("acct:tuomas@lobstermonster.org");
        $_POST = array();
        $this->assertEquals("Controller_Xrd_Lrdd", get_class(Minime::getController("lrdd")));
    }
    
    public function testGetPubsubhubbubCallbackController() {
        MiniMe::initialize();
        $_GET = array();
        $_POST = array();
        $this->assertEquals("Controller_Pubsubhubbub_Callback", get_class(Minime::getController("callback")));
    }
    
    /**
     * @expectedException Exception
     */
    public function testGetControllerExpection() {
        MiniMe::initialize();
        Minime::getController("lrddss");
    }
}